#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: async_crawling_01.py 
@version:
@time: 2023/04/13 
"""
import asyncio

from geekPythonCore.util import async_run_time


async def crawl_page(url):
    print('crawling {}'.format(url))
    sleep_time = int(url.split('_')[-1])
    await asyncio.sleep(sleep_time)
    print('OK {}'.format(url))


async def main(urls):
    tasks = [asyncio.create_task(crawl_page(url)) for url in urls]
    await asyncio.gather(*tasks)


async_run_time(main, ['url_1', 'url_2', 'url_3'])
